﻿/**
Library: Alternative Transitioning
Author: Valentyn Derkach 2007.07.04
// ———————————————————————————————————————————————————————————————————————————————————————————————————————————————————
This is a constant tween processor class. It uses a constant incremental step for calculating a new value.
The equation is 
	newValue = currentValue + sign(endValue - currentValue)*min(incrementalStep, abs(endValue - currentValue))
/**/

package com.bizmlib.transitioning
{

	import com.bizmlib.transitioning.ITweenProcessor;


	public class TweenProcessorConstant extends Object implements ITweenProcessor
	{

		public var changeFactor:Number = 1;
		public var incrementalStep:Number = 1;
		private var maxDValue:Number = 0;


		public function TweenProcessorConstant(incrementalStep:Number){
			if(!isNaN(incrementalStep)){this.incrementalStep = incrementalStep;}
		}


		public function reInit():void{}
		public function onBeforeIteration():void{
			maxDValue = 0;
		}
		public function performCalculation(propertyName:String, currentValue:Number, endValue:Number):Number{
			//trace(this + ".performCalculation(" + arguments + ")");
			var newValue:Number = (Math.abs(currentValue-endValue)<=incrementalStep) ? endValue : currentValue+incrementalStep*(endValue>currentValue?1:-1);
			maxDValue = Math.max(maxDValue, Math.abs(newValue - endValue));
			return newValue;
		}
		public function isFinal():Boolean{
			if(maxDValue == 0){return true;}
			return false;
		}
		public function onAfterIteration():void{
		}

		public function toString():String
		{
			return("[TweenProcessorConstant	incrementalStep=" + incrementalStep + "]");
		}
	}
}